<template>
  <div>
    <div class="pageTopTitle">
      <el-page-header @back="goBack" :content="channel ?  channel.name + '-渠道项目' : '项目查看'">
      </el-page-header>
    </div>
   <div class="app-container">
      <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="80px" size="small">
        <el-form-item label="项目客户" prop="clientId">
          <el-input
            v-model="queryParams.clientId"
            clearable
            placeholder="请输入项目客户"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="app-container mt20">
      <el-table v-loading="loading" :data="projectList">
        <el-table-column label="项目类型" prop="type"/>
        <el-table-column label="项目名称" prop="name"/>
        <el-table-column label="项目负责人" prop="mainUser" width="140px">
          <template slot-scope="scope">
            <span>{{ scope.row.mainUser }}</span>
            <div>{{ scope.row.phone }}</div>
          </template>
        </el-table-column>
        <el-table-column label="项目状态" prop="startAt">
          <template slot-scope="scope">
            <div>
                <span class="el-dropdown-link">
                  <span v-if="scope.row.status === 1" style="color: #FF7D00">推进中</span>
                  <span v-else style="color: #00B42A">已完成</span><i class="el-icon-arrow-down el-icon--right"></i>
                </span>
            </div>
            <div>项目立项：{{ scope.row.startAt }}</div>
            <div v-if="scope.row.endAt">项目完成：{{ scope.row.endAt }}</div>
          </template>
        </el-table-column>
        <el-table-column label="项目总金额" prop="money">
          <template slot-scope="scope">
            <div>
              <span>总金额：{{ scope.row.money }}</span>
            </div>
            <div style="color: #00B42A">
              <span>已收款：{{ scope.row.paidMoney }}</span>
            </div>
            <div style="color: #999">
              <span>未收款：{{ scope.row.money - scope.row.paidMoney }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="项目专家" prop="teacher"/>
        <el-table-column label="项目备注" prop="remark"/>
      </el-table>
      <pagination
        v-show="total>0"
        :limit.sync="queryParams.pageSize"
        :page.sync="queryParams.pageNum"
        :total="total"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { listAccount } from '@/api/web/account'

import { listProject } from '@/api/web/project'

import { getChannel } from '@/api/web/channel'

export default {
  name: 'Project',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 合作项目表格数据
      projectList: [],
      channel: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        clientId: null,
        channelId: null,
        name: null,
        status: null,
        type: null
      },
    }
  },
  created() {
    this.queryParams.channelId = this.$route.params && this.$route.params.channelId;
    if(!this.queryParams.channelId) {
      return
    }
    this.getChannelData(this.queryParams.channelId)
    this.getList()
  },
  methods: {
    goBack() {
      // 返回上一页
      this.$router.go(-1)
    },

    getChannelData(channelId) {
      getChannel(channelId).then(response => {
        this.channel = response.data
      })
    },

    /** 查询合作项目列表 */
    getList() {
      this.loading = true
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows
        this.total = response.total
        this.loading = false
      })

      listAccount().then(resp => {
        this.accountList = resp.rows
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
  }
}
</script>


<style lang="scss" scoped>
.drawer-content {
  padding: 0 30px 80px 20px;
}

.drawer-footer {
  position: absolute;
  bottom: 0;
  box-sizing: border-box;
  text-align: right;
  padding: 16px;
  width: 100%;
  border-top: 1px solid #eee;
  background-color: #fff;
}

::v-deep .el-form-item__label {
  font-weight: 500 !important;
}

::v-deep .el-form--label-top .el-form-item__label {
  padding: 0 0 4px 0 !important;
}
</style>
